#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include<stdlib.h>
using namespace std;



class Linkstack
{
public:
	Linkstack(int size=0):size_(size)
	{
		head_ = new Node();
		size_;

	}
	~Linkstack()
	{
		Node* p = head_->next_;
		while (p != nullptr)
		{
			head_->next_ = p->next_;
			delete p;
			p = head_->next_;
		}


	}
public:
	void push(int val)
	{
		Node* node = new Node(val);
		
		node->next_ = head_->next_;
		head_->next_ = node;
		size_++;
	}
public:
	void pop()
	{
		if (head_->next_ == nullptr)
			throw "stack is empty";
		size_--;
	}
public:
	int top()
	{
		if (head_->next_ == nullptr)
			throw "stack is empty";
		return head_->next_->data_;
	}
public:
	int size()
	{
		return size_;
	}
public:
	bool empty()
	{
		return size_ == 0;
	}

private:
	struct Node
	{
		Node(int data = 0) :data_(data), next_(nullptr) {};
		int data_;
		Node* next_;
	};
	Node* head_;
	int size_;




};
int main()
{
	Linkstack ls;
	ls.push(10);
	cout << ls.top() << " ";
	ls.size();
	cout << ls.size() << " ";
	ls.pop();
	cout << ls.size() << " ";


	return 0;
}